Skip to content

feat(pkg): add --create-parents flag to kpt pkg get - #4854

Merged
liamfallon merged 1 commit into
kptdev:mainfrom
Hrushikesh-ramilla:feat/2824-create-parents-flag
Nov 13, 2026
Merged

liamfallon merged 1 commit into
kptdev:mainfrom
Hrushikesh-ramilla:feat/2824-create-parents-flag

Conversation

@Hrushikesh-ramilla

Copy link
Copy Markdown
Contributor

Description

  • What changed: Adds --create-parents / -p flag to kpt pkg get to automatically create parent directories if they do not exist when fetching a package to a nested destination path.
  • Why it's needed: Currently, running kpt pkg get <REPO> ./apps/my-app/ fails with parent directory "apps" does not exist if the parent directory does not exist yet. Users had to manually create intermediate directories beforehand.
  • How it works:
    • Adds --create-parents / -p flag (and --parents alias) to kpt pkg get.
    • In pkg/lib/util/parse, getDest permits destination paths with non-existent parents when createParents is true.
    • The fetch runner in get.Command.Run uses os.MkdirAll, which creates all leading directories recursively.
    • Defaults to false, preserving the existing strict behavior unless explicitly enabled.

Related Issue(s)


Type of Change

  • New feature
  • Enhancement
  • Documentation
  • Tests

Checklist

  • Code follows project style guidelines
  • Self-reviewed changes
  • Tests added/updated
  • Documentation added/updated
  • All tests and gating checks pass

@Hrushikesh-ramilla
Hrushikesh-ramilla requested review from a team and a balanced review from Copilot November 5, 2026 01:17
@netlify

netlify Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for kptdocs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit e3ae1ba
🔍 Latest deploy log https://app.netlify.com/projects/kptdocs/deploys/6af72d786303fc0e0a11eeb3
😎 Deploy Preview https://deploy-preview-4854--kptdocs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

There are no active review issues for the opt-in parent-directory creation change.

No open issues 🎉

What changed in this PR

Adds opt-in parent-directory creation to kpt pkg get, addressing #2824 while preserving the default error for missing parent directories.

Changes:

  • Adds --create-parents / -p and a hidden --parents alias.
  • Allows nested destinations with missing parents when enabled.
  • Adds parser and CLI flag tests and updates reference documentation and generated help.
File Description
pkg/​lib/​util/​parse/​parse.go Threads the option through parsing and relaxes parent-directory validation when enabled.
pkg/​lib/​util/​parse/​parse_test.go Tests missing-parent validation with the option enabled and disabled.
internal/​docs/​generated/​pkgdocs/​docs.go Adds the flag to generated CLI help.
documentation/​content/​en/​reference/​cli/​pkg/​get/​_index.md Documents the flag and its default.
cli/​pkg/​get/​cmdget.go Registers the flags and passes the option to the parser.
cli/​pkg/​get/​cmdget_test.go Tests default rejection and acceptance with the long and shorthand flags.

Review effort: Balanced

Comment thread cli/pkg/get/cmdget.go Resolved
Comment thread pkg/lib/util/parse/parse.go Resolved
Comment thread pkg/lib/util/parse/parse.go Resolved
Comment thread pkg/lib/util/parse/parse.go Resolved
Comment thread pkg/lib/util/parse/parse.go Resolved
Comment thread pkg/lib/util/parse/parse.go Resolved
Comment thread pkg/lib/util/parse/parse.go Resolved
@Hrushikesh-ramilla

Hrushikesh-ramilla commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Thank you for the review, @aravindtga! Updated as requested:

  • Removed the hidden --parents flag alias in cli/pkg/get/cmdget.go.
  • Simplified createParents from variadic ...bool to an explicit single bool across GitParseArgs, targetFromPkgURL, and getDest, and updated the tests accordingly.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The advertised --parents alias is not registered, causing invocations that use it to fail with an unknown-flag error.

1 open issue

Review effort: Balanced

Comment thread cli/pkg/get/cmdget.go Resolved
@liamfallon

liamfallon commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What confused me on this PR was that I couldn't see where the parent directory is created in the new code so I pointed AI at the PR code. The AI solves the mystery (see below) and it recommends adding a unit test to prove parent directory creation. I agree with the AI. Please add a unit test to show path creation, preferably with a multi-directory parent like dir1/dir2/dir3

AI Generated Review


The parent directories are created, but not by the code the PR adds. I ran the branch's CLI against a local repo, and it works:

kpt pkg get -p file://…/repo.git /missing-parent/my-app created missing-parent/my-app and fetched the package.
The same command without -p fails with parent directory ... does not exist.
The creation happens in
get.go
. That code already calls os.MkdirAll(c.Destination, 0700) when the destination doesn't exist, and MkdirAll creates every missing ancestor. The PR's change in parse.go only skips the early "parent does not exist" error when createParents is set. So the flag works as a gate, but the directory creation is pre-existing behavior.

The unit test doesn't prove this. The create-parents case in cmdget_test.go runs with NoOpRunE, so it only checks argument parsing and never checks that the directory exists. A test that asserts the destination exists after a real fetch would cover the claim.


@Hrushikesh-ramilla

Copy link
Copy Markdown
Contributor Author

Added execution unit tests in \cli/pkg/get/cmdget_test.go\ (\TestCmd_execute_createParents) verifying that both --create-parents\ and -p\ create multi-directory nested parent paths (such as \dir1/dir2/dir3) and fetch the package successfully into destination. Thanks @liamfallon!

@Hrushikesh-ramilla
Hrushikesh-ramilla force-pushed the feat/2824-create-parents-flag branch from 5144af4 to 042a19f Compare November 13, 2026 13:19
@liamfallon

liamfallon commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

@Hrushikesh-ramilla CI is failing now, can you take a look please?

Signed-off-by: hrushikeshramilla <ramillahrushikesh@gmail.com>
@Hrushikesh-ramilla
Hrushikesh-ramilla force-pushed the feat/2824-create-parents-flag branch from 042a19f to e3ae1ba Compare November 13, 2026 15:32
@Hrushikesh-ramilla

Copy link
Copy Markdown
Contributor Author

Rebased on upstream main and resolved the build failure by encapsulating parent creation within the CLI runner, keeping the library API signature unchanged. All tests are passing.

@sonarqubecloud

Copy link
Copy Markdown

@liamfallon
liamfallon merged commit 67a8664 into kptdev:main Nov 13, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

If parent directory does not exist kpt should create it

5 participants